package com.usian.wemedia.controller;

import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.dtos.WmUserDto;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.WmUserControllerApi;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wemedia")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserService wmUserService;

    /**
     * 根据名称查询自媒体账户是否存在
     *
     * @param name
     * @return
     */
    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable String name) {
        return wmUserService.findByName(name);
    }


    /**
     * 保存自媒体账户
     *
     * @param wmUser
     * @return
     */
    @PostMapping("/save")
    @Override
    public ResponseResult saveWmUser(@RequestBody WmUser wmUser) {
        boolean b = wmUserService.saveWmUser(wmUser);
        if(b){
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }else{
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
    }

    /**
     * 根据id查询自媒体用户
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findById/{id}")
    public WmUser findById(@PathVariable Integer id) {
        return wmUserService.getById(id);
    }


}
